<?php
session_start();
include("../db_connect.php");
include("../class/objName.php");

if(isset($_GET['bn'])||isset($_GET['bi'])){

$obj = new objName();
$data = strtoupper($_GET['bn']);
$id = $_GET['bi'];
$tbl = $_GET['tbl'];

if($tbl == "tblbrand"){
	$exist = $obj->isbrandexist($data);
			
		if($exist == "merun"){
			echo "merun";
		}
		else{
			$sql = mysql_query("update tblbrand set brand='$data' where id='$id' ") or die(mysql_error());
		}
}
else if($tbl == "tblmodel"){
	$exist = $obj->ismodelexist2($data);
	if($exist == "merun"){
			echo "merun";
		}
		else{
			$sql = mysql_query("update tblmodel set modelname='$data' where id='$id' ") or die(mysql_error());
		}

}
else{
$exist = $obj->ispartsexist($data);
	if($exist == "merun"){
		echo "merun";
	}
	else{
		$sql = mysql_query("update tblparts set parts='$data' where id='$id' ") or die(mysql_error());
		if(mysql_affected_rows()){
			echo "0";
		}
		else{
			echo "1";
		}
	}

}

}else{

$fname= mysql_real_escape_string(htmlentities(trim($_GET['fname']))); 
$lname =mysql_real_escape_string(htmlentities(trim($_GET['lname'])));
$num= mysql_real_escape_string(htmlentities(trim($_GET['num']))); 
$email = $_GET['email'];

$uname= mysql_real_escape_string(htmlentities(trim($_GET['uname']))); 
$pass =mysql_real_escape_string(htmlentities(trim($_GET['pass'])));
$pass = base64_encode($pass);
$id = $_SESSION['id'];
$sql= "UPDATE tbl_account SET
fname = '".strtoupper($fname)."',
lname = '".strtoupper($lname)."',
contacts = '".$num."',
email = '".$email."',
username = '".$uname."',
password = '".$pass."'
WHERE id = '".$id."' ";
mysql_query($sql) or die(mysql_error());
	if (mysql_affected_rows()){		
		echo "1";
		$_SESSION['fname'] = $fname;
		
	}
	else{		
		echo $_SESSION['fname'];
	}
}

?>